package com.ccs.testcase;

import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import org.openqa.selenium.WebDriver;

import com.ccs.functions.Login;
import com.ccs.functions.Logout;
import com.ccs.functions.Webdriver;
import com.ccs.loas.*;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class Loa_Admin {

	public static String appCode;
	private static String loa_number;
	private static WebDriver driver;
	@SuppressWarnings("unused")
	private static String pin;
	
	@BeforeClass
	public static void startBrowser()throws Exception{
		Webdriver d = new Webdriver();
		driver = d.startUp();
	}
	@Test
	public void a_login_app() throws Exception{
		System.out.println("Start Test: LOGIN WEBAPP");
		Login in = new Login();
		in.app(driver);
		System.out.println("End Test: LOGIN WEBAPP\n");
	}
	@Test
	public void b_create_loa() throws Exception{
		System.out.println("Start Test: Create Loa");
		CreateLOA loa = new CreateLOA();
		String returnedString = loa.create(driver, "notcovered");
		String[] arrString = returnedString.split(",");
		loa_number = arrString[1];
		pin = arrString[0];
		System.out.println("Loa Number: "+loa_number);
		System.out.println("End Test: Create Loa\n");
	}
	@Test
	public void c_logout_loa_app() throws Exception{
		System.out.println("Start Test: LOGOUT WEBAPP");
		Logout out = new Logout();
		out.app(driver);
		System.out.println("End Test: LOGOUT WEBAPP\n");
	}
	@Test
	public void d_login_admin() throws Exception{
		System.out.println("Start Test: LOGIN ADMIN");
		Login in = new Login();
		in.admin(driver);
		System.out.println("End Test: LOGIN ADMIN\n");
	}
	@Test
	public void e_view_new_loa_admin() throws Exception{
		System.out.println("Start Test: VIEW NEW LOA IN ADMIN");
		View_Loa_Admin in = new View_Loa_Admin();
		in.go_to_Loa(driver);
		in.search_loa(driver, loa_number);
		in.verify_loa(driver, "New", loa_number);
		Logout out = new Logout();
		out.admin(driver);
		System.out.println("End Test: VIEW NEW LOA IN ADMIN\n");
	}
	@Test
	public void f_update_to_pending_loa_webapp() throws Exception{
		System.out.println("Start Test: GENERATE LOA");
		Login in = new Login();
		in.app(driver);
		SearchFunctionLoa search_loa = new SearchFunctionLoa();
		search_loa.search(driver, "number", loa_number);
		search_loa.select(driver, "edit");
		Miscellaneous m = new Miscellaneous();
		m.loa_buttons(driver, "final", "");
		Logout out = new Logout();
		out.app(driver);
		System.out.println("End Test: GENERATE LOA\n");
	}
	@Test
	public void g_view_pending_loa_admin() throws Exception{
		System.out.println("Start Test: VIEW PENDING LOA IN ADMIN");
		Login in = new Login();
		in.admin(driver);
		View_Loa_Admin view = new View_Loa_Admin();
		view.go_to_Loa(driver);
		view.search_loa(driver, loa_number);
		view.verify_loa(driver, "Pending", loa_number);
		Logout out = new Logout();
		out.admin(driver);
		System.out.println("End Test: VIEW PENDING LOA IN ADMIN\n");
	}
	@Test
	public void h_update_to_revision_loa_webapp() throws Exception{
		System.out.println("Start Test: UPDATE LOA TO REVISION");
		Login in = new Login();
		in.app(driver);
		SearchFunctionLoa search_loa = new SearchFunctionLoa();
		search_loa.search(driver, "number", loa_number);
		search_loa.select(driver, "review");
		Miscellaneous m = new Miscellaneous();
		m.loa_buttons(driver, "revision", "");
		Logout out = new Logout();
		out.app(driver);
		System.out.println("End Test: UPDATE LOA TO REVISION\n");
	}
	@Test
	public void i_view_revision_loa_admin() throws Exception{
		System.out.println("Start Test: VIEW REVISION LOA IN ADMIN");
		Login in = new Login();
		in.admin(driver);
		View_Loa_Admin view = new View_Loa_Admin();
		view.go_to_Loa(driver);
		view.search_loa(driver, loa_number);
		view.verify_loa(driver, "Reissued", loa_number);
		Logout out = new Logout();
		out.admin(driver);
		System.out.println("End Test: VIEW REVISION LOA IN ADMIN\n");
	}
	@Test
	public void j_update_to_approved_loa_webapp() throws Exception{
		System.out.println("Start Test: UPDATE LOA TO APPROVED");
		Login in = new Login();
		in.app(driver);
		SearchFunctionLoa search_loa = new SearchFunctionLoa();
		search_loa.search(driver, "number", loa_number);
		search_loa.select(driver, "edit");
		Miscellaneous m = new Miscellaneous();
		m.loa_buttons(driver, "final", "");
		search_loa.search(driver, "number", loa_number);
		search_loa.select(driver, "review");
		m.loa_buttons(driver, "approve", "");
		Logout out = new Logout();
		out.app(driver);
		System.out.println("End Test: UPDATE LOA TO APPROVED\n");
	}
	@Test
	public void k_view_approved_loa_admin() throws Exception{
		System.out.println("Start Test: VIEW APPROVED LOA IN ADMIN");
		Login in = new Login();
		in.admin(driver);
		View_Loa_Admin view = new View_Loa_Admin();
		view.go_to_Loa(driver);
		view.search_loa(driver, loa_number);
		view.verify_loa(driver, "Approved", loa_number);
		Logout out = new Logout();
		out.admin(driver);
		System.out.println("End Test: VIEW APPROVED LOA IN ADMIN\n");
	}
	@Test
	public void l_update_to_slmc_loa_webapp() throws Exception{
		System.out.println("Start Test: UPDATE LOA TO SLMC");
		Login in = new Login();
		in.app(driver);
		SearchFunctionLoa search_loa = new SearchFunctionLoa();
		search_loa.search(driver, "number", loa_number);
		search_loa.select(driver, "slmc");
		Miscellaneous m = new Miscellaneous();
		m.loa_buttons(driver, "submit", "2");
		Logout out = new Logout();
		out.app(driver);
		System.out.println("End Test: UPDATE LOA TO SLMC\n");
	}
	@Test
	public void m_view_slmc_loa_admin() throws Exception{
		System.out.println("Start Test: VIEW SUBMITTED TO SLMC LOA IN ADMIN");
		Login in = new Login();
		in.admin(driver);
		View_Loa_Admin view = new View_Loa_Admin();
		view.go_to_Loa(driver);
		view.search_loa(driver, loa_number);
		view.verify_loa(driver, "SubmittedtoSLMC", loa_number);
		Logout out = new Logout();
		out.admin(driver);
		System.out.println("End Test: VIEW SUBMITTED TO SLMC LOA IN ADMIN\n");
	}
	@Test
	public void n_create_disapproved_loa_webapp() throws Exception{
		System.out.println("Start Test: CREATE DISAPPROVED LOA");
		Login in = new Login();
		in.app(driver);
		CreateLOA loa = new CreateLOA();
		String returnedString = loa.create(driver, "notcovered");
		String[] arrString = returnedString.split(",");
		loa_number = arrString[1];
		pin = arrString[0];
		System.out.println("Loa Number: "+loa_number);
		SearchFunctionLoa search_loa = new SearchFunctionLoa();
		search_loa.search(driver, "number", loa_number);
		search_loa.select(driver, "edit");
		Miscellaneous m = new Miscellaneous();
		m.loa_buttons(driver, "final", "");
		search_loa.search(driver, "number", loa_number);
		search_loa.select(driver, "review");
		m.loa_buttons(driver, "disapprove", "");
		Logout out = new Logout();
		out.app(driver);
		System.out.println("End Test: CREATE DISAPPROVED LOA\n");
	}
	@Test
	public void o_view_disapproved_loa_admin() throws Exception{
		System.out.println("Start Test: VIEW DISAPPROVED LOA IN ADMIN");
		Login in = new Login();
		in.admin(driver);
		View_Loa_Admin view = new View_Loa_Admin();
		view.go_to_Loa(driver);
		view.search_loa(driver, loa_number);
		view.verify_loa(driver, "Disapproved", loa_number);
		Logout out = new Logout();
		out.admin(driver);
		System.out.println("End Test: VIEW DISAPPROVED LOA IN ADMIN\n");
	}
	
	

}
